package com.wkbb.sports.websocket;

import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * @author lbh
 * @date 2021年04月25日 14:40:29
 * @description: 在项目启动时对相关资源进行触发初始化和在项目关闭时对相关资源进行释放的监听器
 */
//@WebListener
//@Component
public class ServletListener implements ServletContextListener {

    @Autowired
    private WebSocketServer webSocketServer;
    //private static WebSocketServer webSocketServer;

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        webSocketServer.scheduleQueryWork();
        //webSocketServer.scheduleHeartBeat();
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        webSocketServer.close();
        //webSocketServer.closeHeartBeat();
    }
}
